import { apiRequest } from '../utils/api';
import { Like, LikeResponse } from '../types/like';

// 点赞文章
export const likeArticle = async (articleId: number): Promise<LikeResponse> => {
  return apiRequest<LikeResponse>(`/likes/article/${articleId}`, {
    method: 'POST',
  });
};

// 取消点赞
export const unlikeArticle = async (articleId: number): Promise<LikeResponse> => {
  return apiRequest<LikeResponse>(`/likes/article/${articleId}`, {
    method: 'DELETE',
  });
};

// 检查是否已点赞
export const checkIsLiked = async (articleId: number): Promise<{ isLiked: boolean }> => {
  return apiRequest<{ isLiked: boolean }>(`/likes/check/${articleId}`, {
    method: 'GET',
  });
};

// 获取用户点赞列表
export const getUserLikes = async (params?: { page?: number; limit?: number }): Promise<{
  data: Like[];
  total: number;
  page: number;
  limit: number;
}> => {
  return apiRequest<{
    data: Like[];
    total: number;
    page: number;
    limit: number;
  }>('/likes/user', {
    method: 'GET',
    params,
  });
};

// 获取文章点赞数
export const getArticleLikeCount = async (articleId: number): Promise<{ count: number }> => {
  return apiRequest<{ count: number }>(`/likes/article/${articleId}/count`, {
    method: 'GET',
  });
};